import QtQuick 2.7
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3


//Dialog
Popup{
    id: dialog

    property Item target


    implicitWidth:400
    implicitHeight: 220
    property string dirction:"null"
    readonly property int _spacing: 4

    signal okClicked
    signal cancelClicked

    //modal:true
    //dim:false
    onDirctionChanged: {
        if("left" === dirction){
            dialog.x = target.x - dialog.width - _spacing
            dialog.y = target.y + target.height/2-dialog.height/2
        }
        else if("bottom" === dirction){
            dialog.x = target.x + target.width/2-dialog.width/2
            dialog.y = target.y+target.height + _spacing
        }
    }


    MouseArea {
        id:mouseA
        anchors.fill: parent
        property point clickPos: "0,0"
        acceptedButtons: Qt.LeftButton
        onPressed: {
            clickPos  = Qt.point(mouse.x,mouse.y)
        }
        onPositionChanged: {
            var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
            dialog.x = dialog.x+delta.x
            dialog.y = dialog.y+delta.y
        }
    }



    background: Image{
        source:"file:///" + AppPath.getPath() + "/resource/photo/popImage/" + dirction+ ".png"
        anchors.fill: parent
    }



    onOpened: {
        dialog.focus = true
    }



}
